package com.kehutong.payfees.service.treasure;

//import com.kehutong.payfees.entity.treasure.OrganAccount;
//import com.kehutong.payfees.util.ESignTreasureUrlConfig;
//import org.coraframework.inject.Inject;
//import org.coraframework.json.JSONObject;
//import org.coraframework.mvc.webservice.WebService;
//import org.coraframework.orm.Pool;
//import org.coraframework.orm.jdbc.SQLSession;
//
//@WebService("/sign/treasure/account")
//public class ESignTreasureOrganAccountServiceImpl {
//
//    @Inject
//    protected SQLSession jdbcSession;
//
//    @Inject
//    private ESignTreasureOAuthServiceImpl eSignTreasureOAuthService;
//
//    @Inject
//    private ESignTreasureUrlConfig eSignTreasureUrlConfig;
//
//    public Object pageOrganAccount(JSONObject jsonObject) {
//        return jdbcSession.findPage(OrganAccount.class)
//                .eq(jsonObject, "name", "idNumber", "creator")
//                .eq("deleted", false)
//                .page(jsonObject).exe();
//    }
//
//    public void createOrganAccount(OrganAccount organAccount) throws Exception {
//        JSONObject jsonObject = eSignTreasureUrlConfig.postESignTreasure("/v1/organizations/createByThirdPartyUserId", (http) -> {
//            JSONObject bodyParams = setRequestBody(organAccount);
//            bodyParams.put("creator", organAccount.getCreator());
//            bodyParams.put("thirdPartyUserId", organAccount.getId());
//            http.setBody(bodyParams.toString());
//
//            eSignTreasureOAuthService.setRequestHeaderValue(http);
//        });
//
//        organAccount.setOrgId(jsonObject.getString("orgId"));
//        jdbcSession.insert(organAccount);
//    }
//
//    public Object getOrganAccount(String id) {
//        return Pool.get(OrganAccount.class, id);
//    }
//
//    public void updateOrganAccount(OrganAccount organAccount) throws Exception {
//        eSignTreasureUrlConfig.put("/v1/organizations/" + organAccount.getOrgId(), (http) -> {
//            JSONObject bodyParams = setRequestBody(organAccount);
//            http.setBody(bodyParams.toString());
//
//            eSignTreasureOAuthService.setRequestHeaderValue(http);
//        });
//
//        jdbcSession.updateById(organAccount);
//    }
//
//    public void deleteOrganAccount(String orgId) throws Exception {
//        eSignTreasureUrlConfig.delete("/v1/organizations/" + orgId, (http) -> {
//            eSignTreasureOAuthService.setRequestHeaderValue(http);
//        });
//
//        OrganAccount organAccount = jdbcSession.findOne(OrganAccount.class)
//                .eq(orgId, orgId)
//                .eq("delete", false).exe();
//        organAccount.setDeleted(true);
//        jdbcSession.updateById(organAccount);
//    }
//
//    private JSONObject setRequestBody(OrganAccount organAccount) {
//        JSONObject bodyParams = new JSONObject();
//
//        bodyParams.put("name", organAccount.getName());
//        bodyParams.put("idType", organAccount.getIdType().getId());
//        bodyParams.put("idNumber", organAccount.getIdNumber());
//        bodyParams.put("orgLegalIdNumber", organAccount.getOrgLegalIdNumber());
//        bodyParams.put("orgLegalName", organAccount.getOrgLegalName());
//
//        return bodyParams;
//    }
//}
